package com.mofeng.myshop.controller.admin;


import com.mofeng.myshop.domain.dto.CommandDto;
import com.mofeng.myshop.service.ICommandService;
import com.mofeng.myshop.service.ICommandService;
import com.mofeng.myshop.until.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 管理员后台指令设置 前端控制器
 * </p>
 *
 * @author MoFeng
 * @since 2024-04-14
 */
@RestController
@RequestMapping("/admin/command")
@RequiredArgsConstructor
@PreAuthorize(value = "@permissionService.ROOT()")
@Tag(name = "管理员后台指令设置接口", description = "管理员后台指令设置相关接口")
public class CommandAdminController {

    private final ICommandService commandService;

    @Operation(summary = "获取管理员后台指令列表")
    @GetMapping("/list")
    public R getListAdmin() {
        return commandService.getListAdmin();
    }

    @Operation(summary = "添加管理员后台指令")
    @PostMapping("")
    public R addCommand(@RequestBody CommandDto commandDto) {
        return commandService.addCommand(commandDto);
    }

    @Operation(summary = "修改管理员后台指令")
    @PutMapping("")
    public R updateCommand(@RequestBody CommandDto commandDto) {
        return commandService.updateCommand(commandDto);
    }

    @Operation(summary = "删除管理员后台指令")
    @DeleteMapping("")
    public R delCommand(@RequestParam("id") List<String> ids) {
        return commandService.delCommand(ids);
    }

    @Operation(summary = "执行管理员后台指令")
    @GetMapping("/start")
    public R startCommand(@RequestParam("commandId") String commandId,
                          @RequestParam("mapId") String mapId) {
        return commandService.startCommand(commandId,mapId);
    }

}
